package com.itljm.cxrMarket.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itljm.cxrMarket.entity.Reviews;
import com.itljm.cxrMarket.service.ReviewsService;
import com.itljm.cxrMarket.mapper.ReviewsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReviewsServiceImpl extends ServiceImpl<ReviewsMapper, Reviews> implements ReviewsService{
    @Autowired
    private ReviewsMapper reviewsMapper;
    @Override
    public List<Reviews> selectReviewsPage(Page<Reviews> page, Wrapper<Reviews> entityWrapper) {
        return reviewsMapper.selectReviewsPage(page, entityWrapper);
    }

    @Override
    public boolean addReview(Reviews review) {
        Reviews isExists = reviewsMapper.getReviewToProductsByUserIdAndProductId(review.getUserId(), review.getProductId());
        if (isExists != null) return false;
        return reviewsMapper.insert(review) > 0;
    }

    @Override
    public boolean updateReview(Reviews review) {
        return reviewsMapper.updateById(review) > 0;
    }

    @Override
    public boolean updateLikeNum(Long userId, Integer reviewId) {
        return reviewsMapper.updateLikeNum(userId, reviewId) > 0;
    }

    @Override
    public boolean removeReview(Long userId) {
        return reviewsMapper.deleteById(userId) > 0;
    }

    @Override
    public Reviews selectLikeTop(Integer productId) {
        return reviewsMapper.selectLikeTop(productId);
    }
}




